package com.java.com.syun.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class NIOClient {

    public static void main(String[] args) throws IOException {
        // 获取通道
        SocketChannel socketChannel = SocketChannel.open(new InetSocketAddress("127.0.0.1", 9001));
        socketChannel.configureBlocking(false);
        // 分配缓冲区
        ByteBuffer buf = ByteBuffer.allocate(1024);
        // 发送数据
        String str = "你好，服务端";
        buf.put(str.getBytes());
        buf.flip();
        socketChannel.write(buf);
        buf.clear();
        // 关闭通道
        socketChannel.close();
    }
}

